/*
 * Project : Linuxbox
 * File    : UserManEdit.java
 * Version : 1.0
 * Author  : Kevin Zhang
 *
 * Copyright (c) 2000-2001 by Linuxbox, Inc.
 * All rights reserved.
 */
package linuxbox.addrbook.servlet;

import javax.servlet.http.*;

import java.util.*;

import linuxbox.admin.logic.*;
import linuxbox.common.*;

public class UserSearchAction extends Action {
	protected static String successJSP = null;
	
    public void doAction(HttpSession aSession, BoxSession aBoxSession, 
    HttpServletRequest req, HttpServletResponse res) throws Exception {
		String firstName = req.getParameter("FIRST_NAME");
		String lastName = req.getParameter("LAST_NAME");
		String phone = req.getParameter("PHONE");
		String email = req.getParameter("EMAIL");
	
		StringBuffer where = new StringBuffer();
		if (firstName != null && firstName.length() > 0) {
		    where.append(" where firstname='" + firstName + "'");
		}
		if (lastName != null && lastName.length() > 0) {
		    if (where.length() > 0) 
		        where.append(", ");
		    else 
		        where.append(" where ");
		    where.append("lastname='" + lastName + "'");
		}
		if (phone != null && phone.length() > 0) {
		    if (where.length() > 0) 
		        where.append(", ");
		    else 
		        where.append(" where ");
		    where.append("phone='" + phone + "'");
		}
		if (email != null && email.length() > 0) {
		    if (where.length() > 0) 
		        where.append(", ");
		    else 
		        where.append(" where ");
		    where.append("email='" + email + "'");
		}
		
		UserManager um = UserManager.getInstance();
		List users = um.findUsers(where.toString());
		req.setAttribute("USER_LIST", users);
    	sendFile(successJSP, req, res);
	}

	public void setSuccessJSP(String str) {
		successJSP = str;
	}
}
